package com.yulan.hash;


import org.junit.Test;

import java.util.HashMap;

/**
 * URL 的加密与解密
 */
public class LeetCode_535_TinyURL {

    HashMap<Integer,String> map = new HashMap<>();

    // Encodes a URL to a shortened URL.
    public String encode(String longUrl) {
        map.put(longUrl.hashCode(),longUrl);
        return "http://tinyurl.com/" + longUrl.hashCode();
    }

    // Decodes a shortened URL to its original URL.
    public String decode(String shortUrl) {
        return map.get(Integer.parseInt(shortUrl.replace("http://tinyurl.com/","")));
    }

    @Test
    public void test(){

    }
}
